#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdbool.h>
#include<stdlib.h>

struct TreeNode {
    int val;
    struct TreeNode* left;
    struct TreeNode* right;

};

struct TreeNode* BuyNode(int x)
{
    struct TreeNode* node = (struct TreeNode*)malloc(sizeof(struct TreeNode));
    if (node == NULL)
    {
        perror("malloc fail");
        return NULL;
    }

    node->val = x;
    node->left = NULL;
    node->right = NULL;

    return node;
}

bool isUnivalTree(struct TreeNode* root) {
    if (!root) {
        return true;
    }
    if (root->left) {
        if (root->val != root->left->val || !isUnivalTree(root->left)) {
            return false;
        }
    }
    if (root->right) {
        if (root->val != root->right->val || !isUnivalTree(root->right)) {
            return false;
        }
    }
    return true;
}


bool isUnivalTree1(struct TreeNode* root) {
    if (root == NULL) {
        return true;
    }
    if (root->left) {
        if (root->left->val != root->val) {
            return false;
        }
        if (isUnivalTree(root->left)) {
            return false;
        }
    }
    if (root->right) {
        if (root->right->val != root->val) {
            return false;
        }
        if (isUnivalTree(root->right)) {
            return false;
        }
    }
    return true;
}
int main() {
    struct TreeNode* node1 = BuyNode(1);
    struct TreeNode* node2 = BuyNode(1);
    struct TreeNode* node3 = BuyNode(1);
    struct TreeNode* node4 = BuyNode(1);
    struct TreeNode* node5 = BuyNode(1);
    struct TreeNode* node6 = BuyNode(1);
    node1->left = node2;
  

    isUnivalTree1(node1);
    return 0;
}